package com.szxy.common.redis.service.impl;

import com.szxy.common.redis.service.ItemService;
import com.szxy.pojo.TbItem;
import com.szxy.pojo.TbItemDesc;
import com.szxy.pojo.TbItemParamItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

/**
 * @Auther:zwer
 * @Date:2019/9/11 21:41
 * @Description:com.szxy.common.redis.service.impl
 * @Version:1.0
 **/
@Service
public class ItemServiceImpl implements ItemService {

    @Autowired
    private RedisTemplate<String,Object> redisTemplate;
    @Value("${REDIS_FRONT_ITEMINFO_KEY}")
    private String REDIS_FRONT_ITEMINFO_KEY;
    @Value("${REDIS_FRONT_ITEMDESC_KEY}")
    private String REDIS_FRONT_ITEMDESC_KEY;
    @Value("${REDIS_FRONT_ITEMPARAMITEM_KEY}")
    private String REDIS_FRONT_ITEMPARAMITEM_KEY;

    @Override
    public void insertItemInfo(TbItem item) {
        this.redisTemplate.opsForValue().
                set(this.REDIS_FRONT_ITEMINFO_KEY+":"+item.getId(),item);
    }

    @Override
    public TbItem getItemInfo(Long itemId) {
        return (TbItem) this
                .redisTemplate.opsForValue()
                .get(this.REDIS_FRONT_ITEMINFO_KEY+":"+itemId);
    }

    @Override
    public void insertItemDesc(TbItemDesc itemDesc) {
        this.redisTemplate.opsForValue()
                .set(this.REDIS_FRONT_ITEMDESC_KEY+":"+ itemDesc.getItemId(),itemDesc);
    }

    @Override
    public TbItemDesc getItemDesc(Long itemId) {
        return (TbItemDesc) this
                .redisTemplate.opsForValue()
                .get(this.REDIS_FRONT_ITEMDESC_KEY+":"+itemId);
    }

    @Override
    public void insertItemParamItem(TbItemParamItem itemParamItem) {
        this.redisTemplate.opsForValue()
                .set(this.REDIS_FRONT_ITEMPARAMITEM_KEY+":"+itemParamItem.getItemId(),itemParamItem);
    }

    @Override
    public TbItemParamItem getItemParamItem(Long itemId) {
        return (TbItemParamItem) this.redisTemplate.opsForValue()
                .get(this.REDIS_FRONT_ITEMPARAMITEM_KEY+":"+itemId);
    }
}
